<!-- 底部导航 -->
<template>
    <div id='anv_container'>
        <div class="nav_item1" @click="selectHandle('chat')">
            <img class="nav_icon" :src="'../../public/navs/' + chatIco + '.png'" alt="" srcset="">
            <div id="nav1_text" class="nav_text" :class="{selectedText: commonStore.selectedNav == 'chat'}">首页</div>
        </div>
        <div id="cahrt">|</div>
        <div class="nav_item2" @click="selectHandle('contact')">
            <img class="nav_icon" :src="'../../public/navs/' + contactIco + '.png'" alt="" srcset="">
            <div class="nav_text" :class="{selectedText: commonStore.selectedNav != 'chat'}">联系</div>
        </div>
    </div>
</template>
<script setup>
import { useCommonState } from "../store/commonState"
import { ref } from "vue"

// 实例化Pinia自定义sotore
const commonStore = useCommonState()

let chatIco = ref("nav_chat_active");
let contactIco = ref("nav_contact")

// 选择/切换导航处理器
function selectHandle(navStr) {
    // 更新Pinia中值
    commonStore.updateNav(navStr)
    // 变更图标
    if(navStr == "chat"){
        chatIco.value = "nav_chat_active";
        contactIco.value = "nav_contact";
    }else{
        chatIco.value = "nav_chat";
        contactIco.value = "nav_contact_active";
    }
}
</script>
<style scoped>
#anv_container {
    max-width: 700px;
    padding: 5px 10px;
    box-sizing: border-box;
    width: 100%;
    background-color: #eeeeee;
    display: flex;
    justify-content: space-around;
    position: fixed;
    bottom: 0px;
    left: 0px;
}

.selectedText{
    color: #32ce3c;
}

#cahrt{
    color: #cecece;
    display: flex;
    justify-content: center;
    align-items: center;
}

.nav_item1 {
    position: relative;
    left: 20px;
}

.nav_item1 img{
    width: 42px;
}

.nav_item2 {
    position: relative;
    right: 20px;
}

.nav_item1,
.nav_item2 {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-content: center;
    font-size: 12px;
}

#nav1_text {
    position: relative;
    left: 7px;
}

.nav_text {
    padding-top: 2px;
    margin-left: 2px;
}
</style>